package com.mall.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.mall.bean.Goods;
import com.mall.bean.Keyword;
import com.mall.bean.Search;
import com.mall.service.IGoodsService;
import com.mall.service.IKeywordService;
import com.mall.service.ISearchService;

@Controller
public class HotSearchController {

	@Resource
	private ISearchService searchService;

	@Resource
	private IKeywordService keywordService;

	@Resource
	private IGoodsService goodsService;

	//热搜展示
	@RequestMapping("index-1")
	public String keyword(Model model, Search search, Goods goods) {

		//热搜
		List<String> key = keywordService.findKeyword();
		if (!key.isEmpty()) {
			search.setGoods_name(key.get(0));
			List<Search> key1 = searchService.findKeyword(search);
			model.addAttribute("key1", key1);

			search.setGoods_name(key.get(1));
			List<Search> key2 = searchService.findKeyword(search);
			model.addAttribute("key2", key2);

			search.setGoods_name(key.get(2));
			List<Search> key3 = searchService.findKeyword(search);
			model.addAttribute("key3", key3);

			search.setGoods_name(key.get(3));
			List<Search> key4 = searchService.findKeyword(search);
			model.addAttribute("key4", key4);

			search.setGoods_name(key.get(4));
			List<Search> key5 = searchService.findKeyword(search);
			model.addAttribute("key5", key5);

			search.setGoods_name(key.get(5));
			List<Search> key6 = searchService.findKeyword(search);
			model.addAttribute("key6", key6);

			search.setGoods_name(key.get(6));
			List<Search> key7 = searchService.findKeyword(search);
			model.addAttribute("key7", key7);

			search.setGoods_name(key.get(7));
			List<Search> key8 = searchService.findKeyword(search);
			model.addAttribute("key8", key8);

			//闲置商品
			List<Goods> goodsAll = goodsService.findGoods(goods);
			model.addAttribute("goodsAll", goodsAll);

			//热搜列表展示
			model.addAttribute("key", key);
			System.out.println(key);
		}
		return "index-1";
	}


}
